package scantask.client.presentationLayer;

import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import scantask.client.domainLayer.ControllerInterface;
import scantask.server.domainLayer.Exceptions.LoginException;

public class LogoutPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	// The world window of NASA.
	private WorldWindow _wwd;
	
	// The client controller.
	private ControllerInterface _controller;
	
	public LogoutPanel(WorldWindow wwd, ControllerInterface controller)
    {
		super();
		this.setLayout(null);
		this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
		
		this._wwd = wwd;
        this._controller = controller;
        
     // Button for logout.
        JButton logout = new JButton("Logout");
        logout.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				try {
					LogoutPanel.this._controller.logout();
					JOptionPane.showMessageDialog(
							null, "Thank you for using 3D Visualization for" +
									" location based information",
							"Logout succeeded  ", JOptionPane.INFORMATION_MESSAGE);
					LogoutPanel.this._wwd.getView().goTo(new Position(
							LatLon.fromDegrees(36, 15),
							27000000), 27000000);
					FunctionalityPanel.changeToLoginPanel();
					UpperPanel.changeToLoginPanel();
				} catch (LoginException e) {
				}
			}
		});
        logout.setBounds(10, 10, 100, 25);
        this.add(logout);

    }
}
